﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity.IRepository.Project;
using Entity.ProjectEnt;
using ZFine.Data;
using System.Reflection;

namespace Logic.Repository.Project
{
    public class CarriageRepository : RepositoryBase<CarriageEntity>, ICarriageRepository
    {
        public int UpdateN(CarriageEntity entity)
        {
            dbcontext.Set<CarriageEntity>().Attach(entity);
            PropertyInfo[] props = entity.GetType().GetProperties();
            foreach (PropertyInfo prop in props)
            {
                if (prop.PropertyType.FullName.Contains("Entity"))
                {
                    break;
                }
                if (prop.GetValue(entity, null) != null)
                {
                    if (prop.GetValue(entity, null).ToString() == "&nbsp;")
                        dbcontext.Entry(entity).Property(prop.Name).CurrentValue = null;
                    dbcontext.Entry(entity).Property(prop.Name).IsModified = true;
                }
            }
            return dbcontext.SaveChanges();
        }
    }
}
